<template>
  <el-container id="home">
    <el-header>
      <div>
        <img src="@/assets/img/xuan.jpg" >
        <span>后台管理系统</span>
        </div>
      <el-button type="info" @click="loginOut">退出</el-button></el-header>
    <el-container>
      <el-aside :width="isToggle? '64px':'200px'">
        <div class="toggleBtn" @click="toggleMenu">
          |||
        </div>
        <homeMenu :menuList="menuList" :collapse="isToggle"></homeMenu>

      </el-aside>
      <el-main>
        <el-breadcrumb separator-class="el-icon-arrow-right">
          <el-breadcrumb-item :to="{ path: '/home' }">首页</el-breadcrumb-item>
          <el-breadcrumb-item
              v-for="(item, index) in breadcrumb"
              :key="index">
            {{item.meta.title}}
          </el-breadcrumb-item>
        </el-breadcrumb>

        <router-view></router-view>
      </el-main>
    </el-container>
  </el-container>
</template>

<script>
  import homeMenu from '@/component/homeMenu.vue'
  export default {
    components:{
      homeMenu
    },
    data(){
      return{
      menuList:null,
      isToggle:false
      }
    },
    computed:{
      breadcrumb(){
        return this.$route.matched
      }
    },
    created() {
     this.getMenuList()
    },
    methods:{
      toggleMenu(){
        this.isToggle = !this.isToggle
      },
      loginOut(){
        window.sessionStorage.clear()
        this.$router.push("/login")
      },
     async getMenuList(){
       const {data: res} = await this.$http.get('menus')
       if(res.meta.status !=200) return this.$Message.error(res.meta.msg)
       this.menuList = res.data
      }
    }
  }
</script>

<style lang="less" scoped>
  #home{
    height: 100vh;
    .el-header{
      background-color: #23262E;
      display: flex;        
      align-items: center;
      justify-content: space-between;
      
      div{
        color: #fff;
        display: flex;
        align-items: center;
        font-size: 20px;
        img{
          width: 50px;
          border-radius: 50%;
          height: 50px;
          margin-right: 10px;
        }
      }
    }
    .el-aside{
      background-color: #393D49;
    }
    .el-main{
      background-color: #fff;
    }
  }
  .toggleBtn{
    width: 100%;
    color: #fff;
    background-color: #4a5064;
    text-align: center;
    font-size: 10px;
    line-height: 24px;
    letter-spacing: .2em;
    cursor: pointer;
  }
</style>
